home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / term-source.lha / Extras / Source / term-Source.lha / ImportPanel.c < prev    next >
C/C++ Source or Header  |  1995-02-15  |  7KB  |  342 lines

  1. /*
  2. **    ImportPanel.c
  3. **
  4. **    Editing panel for phone unit settings
  5. **
  6. **    Copyright © 1990-1995 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12. enum    {    GAD_LIST=1,GAD_REPLACE,GAD_APPEND,GAD_CANCEL };
  13.  
  14.     /* ListViewRender():
  15.      *
  16.      *    This callback routine is responsible for rendering
  17.      *    the single listview entries.
  18.      */
  19.  
  20. STATIC ULONG __saveds __asm
  21. ListViewRender(register __a0 struct Hook *Hook,register __a1 struct LVDrawMsg *Msg,register __a2 struct Node *Node)
  22. {
  23.         /* We only know how to redraw lines. */
  24.  
  25.     if(Msg -> lvdm_MethodID == LV_DRAW)
  26.     {
  27.         struct RastPort    *RPort    = Msg -> lvdm_RastPort;
  28.         LONG         Left    = Msg -> lvdm_Bounds . MinX,
  29.                  Top    = Msg -> lvdm_Bounds . MinY,
  30.                  Width    = Msg -> lvdm_Bounds . MaxX - Msg -> lvdm_Bounds . MinX + 1,
  31.                  Height    = Msg -> lvdm_Bounds . MaxY - Msg -> lvdm_Bounds . MinY + 1,
  32.                  FgPen,BgPen,
  33.                  Len,LabelLen;
  34.         STRPTR         String;
  35.  
  36.         String = &Node -> ln_Name[6];
  37.  
  38.             /* Determine the rendering pens. */
  39.  
  40.         switch(Msg -> lvdm_State)
  41.         {
  42.             case LVR_SELECTEDDISABLED:
  43.             case LVR_NORMALDISABLED:
  44.             case LVR_NORMAL:
  45.  
  46.                 FgPen = Msg -> lvdm_DrawInfo -> dri_Pens[TEXTPEN];
  47.                 BgPen = Msg -> lvdm_DrawInfo -> dri_Pens[BACKGROUNDPEN];
  48.                 break;
  49.  
  50.             case LVR_SELECTED:
  51.  
  52.                 FgPen = Msg -> lvdm_DrawInfo -> dri_Pens[FILLTEXTPEN];
  53.                 BgPen = Msg -> lvdm_DrawInfo -> dri_Pens[FILLPEN];
  54.                 break;
  55.         }
  56.  
  57.         SetAPen(RPort,BgPen);
  58.         RectFill(RPort,Left,Top,Left + 1,Top + Height - 1);
  59.  
  60.         Left    += 2;
  61.         Width    -= 2;
  62.  
  63.             /* Set the rendering pens. */
  64.  
  65.         SetDrMd(RPort,JAM2);
  66.         SetAPen(RPort,FgPen);
  67.         SetBPen(RPort,BgPen);
  68.  
  69.             /* Determine length of vanilla name. */
  70.  
  71.         LabelLen = strlen(String);
  72.  
  73.             /* Try to make it fit. */
  74.  
  75.         while(LabelLen > 0 && (Len = TextLength(RPort,String,LabelLen)) > Width)
  76.             LabelLen--;
  77.  
  78.             /* Print the vanilla name if possible. */
  79.  
  80.         if(LabelLen)
  81.         {
  82.             Move(RPort,Left,Top + RPort -> Font -> tf_Baseline);
  83.             Text(RPort,String,LabelLen);
  84.  
  85.             Left    += Len;
  86.             Width    -= Len;
  87.         }
  88.  
  89.             /* Fill the area to follow the vanilla name. */
  90.  
  91.         if(Width > 0)
  92.         {
  93.             SetAPen(RPort,BgPen);
  94.             RectFill(RPort,Left,Top,Left + Width - 1,Top + Height - 1);
  95.         }
  96.  
  97.             /* If the item happens to be disabled, draw the cross-hatch
  98.              * pattern across it.
  99.              */
  100.  
  101.         if(Msg -> lvdm_State == LVR_SELECTEDDISABLED || Msg -> lvdm_State == LVR_NORMALDISABLED)
  102.         {
  103.             SetDrMd(RPort,JAM1);
  104.  
  105.             SetAPen(RPort,Msg -> lvdm_DrawInfo -> dri_Pens[BLOCKPEN]);
  106.  
  107.             SetAfPt(RPort,(UWORD *)&Ghosting,1);
  108.  
  109.             RectFill(RPort,Msg -> lvdm_Bounds . MinX,Msg -> lvdm_Bounds . MinY,Msg -> lvdm_Bounds . MaxX,Msg -> lvdm_Bounds . MaxY);
  110.  
  111.             SetAfPt(RPort,NULL,0);
  112.         }
  113.  
  114.         return(LVCB_OK);
  115.     }
  116.     else
  117.         return(LVCB_UNKNOWN);
  118. }
  119.  
  120. BYTE __regargs
  121. ImportPanel(struct PhoneEntry *Entry,struct List *PhoneList,struct List *TimeDateList)
  122. {
  123.     struct LayoutHandle    *Handle;
  124.     BYTE             MadeChanges = FALSE;
  125.  
  126.     if(!TimeDateList)
  127.         TimeDateList = (struct List *)&Entry -> TimeDateList;
  128.  
  129.     if(Handle = LT_CreateHandleTags(Window -> WScreen,
  130.         LH_LocaleHook,    &LocaleHook,
  131.     TAG_DONE))
  132.     {
  133.         struct Window *PanelWindow;
  134.  
  135.         LT_New(Handle,
  136.             LA_Type,    VERTICAL_KIND,
  137.         TAG_DONE);
  138.         {
  139.             LT_New(Handle,
  140.                 LA_Type,    VERTICAL_KIND,
  141.                 LA_LabelID,    MSG_V36_0088,
  142.             TAG_DONE);
  143.             {
  144.                 STATIC struct Hook ListViewHook =
  145.                 {
  146.                     {NULL},
  147.                     (HOOKFUNC)ListViewRender
  148.                 };
  149.  
  150.                 LONG i,Index = -1;
  151.  
  152.                 for(i = 0 ; i < NumPhoneEntries ; i++)
  153.                 {
  154.                     if(Entry == Phonebook[i])
  155.                     {
  156.                         Index = i;
  157.  
  158.                         break;
  159.                     }
  160.                 }
  161.  
  162.                 LT_New(Handle,
  163.                     LA_Type,    LISTVIEW_KIND,
  164.                     LA_LabelID,    MSG_GLOBAL_NAME_LIST_GAD,
  165.                     LA_ID,        GAD_LIST,
  166.                     LA_Chars,    50,
  167.                     LA_Lines,    10,
  168.                     LALV_Link,    NIL_LINK,
  169.                     LALV_CursorKey,    TRUE,
  170.                     LALV_MaxGrowY,    20,
  171.                     LALV_ResizeY,    TRUE,
  172.                     GTLV_Selected,    Index,
  173.                     GTLV_CallBack,    &ListViewHook,
  174.                     GTLV_Labels,    PhoneList,
  175.                 TAG_DONE);
  176.  
  177.                 LT_EndGroup(Handle);
  178.             }
  179.  
  180.             LT_New(Handle,
  181.                 LA_Type,VERTICAL_KIND,
  182.             TAG_DONE);
  183.             {
  184.                 LT_New(Handle,
  185.                     LA_Type,    XBAR_KIND,
  186.                     LAXB_FullSize,    TRUE,
  187.                 TAG_DONE);
  188.  
  189.                 LT_EndGroup(Handle);
  190.             }
  191.  
  192.             LT_New(Handle,LA_Type,HORIZONTAL_KIND,
  193.                 LAGR_Spread,    TRUE,
  194.             TAG_DONE);
  195.             {
  196.                 LT_New(Handle,
  197.                     LA_Type,    BUTTON_KIND,
  198.                     LA_LabelID,    MSG_IMPORTPANEL_REPLACE_RATES_GAD,
  199.                     LA_ID,        GAD_REPLACE,
  200.                     GA_Disabled,    TRUE,
  201.                     LABT_ExtraFat,    TRUE,
  202.                 TAG_DONE);
  203.  
  204.                 LT_New(Handle,
  205.                     LA_Type,    BUTTON_KIND,
  206.                     LA_LabelID,    MSG_IMPORTPANEL_APPEND_RATES_GAD,
  207.                     LA_ID,        GAD_APPEND,
  208.                     GA_Disabled,    TRUE,
  209.                     LABT_ExtraFat,    TRUE,
  210.                 TAG_DONE);
  211.  
  212.                 LT_New(Handle,
  213.                     LA_Type,    BUTTON_KIND,
  214.                     LA_LabelID,    MSG_GLOBAL_CANCEL_GAD,
  215.                     LA_ID,        GAD_CANCEL,
  216.                     LABT_EscKey,    TRUE,
  217.                     LABT_ExtraFat,    TRUE,
  218.                 TAG_DONE);
  219.  
  220.                 LT_EndGroup(Handle);
  221.             }
  222.  
  223.             LT_EndGroup(Handle);
  224.         }
  225.  
  226.         if(PanelWindow = LT_Layout(Handle,LocaleString(MSG_IMPORTPANEL_IMPORT_RATES_TXT),NULL,0,0,IDCMP_CLOSEWINDOW,0,
  227.             LAWN_HelpHook,        &GuideHook,
  228.             LAWN_Parent,        Window,
  229.             WA_DepthGadget,        TRUE,
  230.             WA_CloseGadget,        TRUE,
  231.             WA_DragBar,        TRUE,
  232.             WA_RMBTrap,        TRUE,
  233.             WA_Activate,        TRUE,
  234.         TAG_DONE))
  235.         {
  236.             struct IntuiMessage    *Message;
  237.             BOOLEAN             Done = FALSE;
  238.             ULONG             MsgClass,
  239.                          MsgQualifier;
  240.             UWORD             MsgCode;
  241.             struct Gadget        *MsgGadget;
  242.             LONG             Selected = ~0;
  243.  
  244.             GuideContext(CONTEXT_IMPORT);
  245.  
  246.             LT_ShowWindow(Handle,TRUE);
  247.  
  248.             PushWindow(PanelWindow);
  249.  
  250.             do
  251.             {
  252.                 if(Wait(PORTMASK(PanelWindow -> UserPort) | SIG_BREAK) & SIG_BREAK)
  253.                     break;
  254.  
  255.                 while(Message = (struct IntuiMessage *)LT_GetIMsg(Handle))
  256.                 {
  257.                     MsgClass    = Message -> Class;
  258.                     MsgQualifier    = Message -> Qualifier;
  259.                     MsgCode        = Message -> Code;
  260.                     MsgGadget    = (struct Gadget *)Message -> IAddress;
  261.  
  262.                     LT_ReplyIMsg(Message);
  263.  
  264.                     if(MsgClass == IDCMP_CLOSEWINDOW)
  265.                         Done = TRUE;
  266.  
  267.                     if(MsgClass == IDCMP_GADGETUP)
  268.                     {
  269.                         switch(MsgGadget -> GadgetID)
  270.                         {
  271.                             case GAD_LIST:
  272.  
  273.                                 if(Entry != Phonebook[MsgCode])
  274.                                 {
  275.                                     if(Selected == ~0)
  276.                                     {
  277.                                         LT_SetAttributes(Handle,GAD_REPLACE,
  278.                                             GA_Disabled,    FALSE,
  279.                                         TAG_DONE);
  280.  
  281.                                         LT_SetAttributes(Handle,GAD_APPEND,
  282.                                             GA_Disabled,    FALSE,
  283.                                         TAG_DONE);
  284.                                     }
  285.  
  286.                                     Selected = MsgCode;
  287.                                 }
  288.                                 else
  289.                                 {
  290.                                     if(Selected != ~0)
  291.                                     {
  292.                                         LT_SetAttributes(Handle,GAD_REPLACE,
  293.                                             GA_Disabled,    TRUE,
  294.                                         TAG_DONE);
  295.  
  296.                                         LT_SetAttributes(Handle,GAD_APPEND,
  297.                                             GA_Disabled,    TRUE,
  298.                                         TAG_DONE);
  299.  
  300.                                         Selected = ~0;
  301.                                     }
  302.                                 }
  303.  
  304.                                 break;
  305.  
  306.                             case GAD_APPEND:
  307.  
  308.                                 CopyTimeDateList((struct List *)&Phonebook[Selected] -> TimeDateList,TimeDateList,TRUE);
  309.  
  310.                                 Done = MadeChanges = TRUE;
  311.  
  312.                                 break;
  313.  
  314.                             case GAD_REPLACE:
  315.  
  316.                                 FreeTimeDateList(TimeDateList);
  317.  
  318.                                 CopyTimeDateList((struct List *)&Phonebook[Selected] -> TimeDateList,TimeDateList,FALSE);
  319.  
  320.                                 Done = MadeChanges = TRUE;
  321.  
  322.                                 break;
  323.  
  324.                             case GAD_CANCEL:
  325.  
  326.                                 Done = TRUE;
  327.                                 break;
  328.                         }
  329.                     }
  330.                 }
  331.             }
  332.             while(!Done);
  333.  
  334.             PopWindow();
  335.         }
  336.  
  337.         LT_DeleteHandle(Handle);
  338.     }
  339.  
  340.     return(MadeChanges);
  341. }
  342.